
/*
UDPSocket

发送端思路:
1.创建一个udp的socket对象
2.创建需要发送的数据,并进行封包处理
3.发送数据
4.关闭资源


///1.创建socket并绑定端口8888
		DatagramSocket s = new DatagramSocket(8888);

		///2.创建发送数据,并进行封包处理
		byte[] data = "You are SB".getBytes();
		DatagramPacket dp = new DatagramPacket(data,data.length);
		///3.发送数据包
		s.send(dp);

		///4.关闭资源
		s.close();

*/

import java.net.*;
import java.lang.*;
import java.io.*;

class UdpSocket{

	public static void main(String[] args) throws Exception
	{
		DatagramSocket s = new DatagramSocket();
		SocketSend send = new SocketSend(s);
		send.sendData();
	}

}

class SocketSend{

	private DatagramSocket s;

	SocketSend(DatagramSocket s){
		this.s = s;
	}


	public void sendData() throws Exception
	{
		///2.创建发送数据,并进行封包处理
		byte[] data = "You are SB".getBytes();
		DatagramPacket dp = new DatagramPacket(data,data.length);
		///3.发送数据包
		this.s.send(dp);

		///4.关闭资源
		//this.s.close();
	}
}














